package com.xjl.common.web.Res;

import lombok.Data;

import java.io.Serializable;

@Data
public class Result<T> implements Serializable {

    private Boolean success;

    private Integer code;

    private String message;

    private T data;

    private Result(){};

    public static Result ok(){
        Result<Object> result = new Result<>();
        result.setCode(ResultCode.SUCCESS);
        result.setMessage(ResultMessage.SUCCESS);
        return result;
    }
    public static Result error(){
        Result<Object> result = new Result<>();
        result.setCode(ResultCode.ERROR);
        result.setMessage(ResultMessage.ERROR);
        return result;
    }

    public static<T> Result ok(T data){
        Result<Object> result = new Result<>();
        result.setCode(ResultCode.SUCCESS);
        result.setMessage(ResultMessage.SUCCESS);
        result.setData(data);
        return result;
    }
    public static<T> Result error(T data){
        Result<Object> result = new Result<>();
        result.setCode(ResultCode.ERROR);
        result.setMessage(ResultMessage.ERROR);
        result.setData(data);
        return result;
    }
    public static<T> Result ok(String message ,T data){
        Result<Object> result = new Result<>();
        result.setCode(ResultCode.SUCCESS);
        result.setMessage(message);
        result.setData(data);
        return result;
    }
    public static<T> Result error(String message ,T data){
        Result<Object> result = new Result<>();
        result.setCode(ResultCode.ERROR);
        result.setMessage(message);
        result.setData(data);
        return result;
    }
    public static<T> Result ok(Integer code ,String message ,T data){
        Result<Object> result = new Result<>();
        result.setCode(code);
        result.setMessage(message);
        result.setData(data);
        return result;
    }

    public static<T> Result error(Integer code ,String message ,T data){
        Result<Object> result = new Result<>();
        result.setCode(code);
        result.setMessage(message);
        result.setData(data);
        return result;
    }
}
